package com.nebula.util;

public class UsernameEncryptionUtil {

	public static String encryptionUsername(String username){
		
		int length = username.length();
		
		if(length >= 3 && length <= 6){
			username = username.replaceAll("(?<=[\u4e00-\u9fa5\\w]{1})[\u4e00-\u9fa5\\w](?=[\u4e00-\u9fa5\\w]{1})","*");
		}else if(length == 7){
			username = username.replaceAll("(?<=[\u4e00-\u9fa5\\w]{1})[\u4e00-\u9fa5\\w](?=[\u4e00-\u9fa5\\w]{2})","*");
		}else if(length == 8){
			username = username.replaceAll("(?<=[\u4e00-\u9fa5\\w]{2})[\u4e00-\u9fa5\\w](?=[\u4e00-\u9fa5\\w]{2})","*");
		}else if(length == 9){
			username = username.replaceAll("(?<=[\u4e00-\u9fa5\\w]{2})[\u4e00-\u9fa5\\w](?=[\u4e00-\u9fa5\\w]{3})","*");
		}else if(length == 10){
			username = username.replaceAll("(?<=[\u4e00-\u9fa5\\w]{3})[\u4e00-\u9fa5\\w](?=[\u4e00-\u9fa5\\w]{3})","*");
		}else if(length >= 11){
			username = username.replaceAll("(?<=[\u4e00-\u9fa5\\w]{3})[\u4e00-\u9fa5\\w](?=[\u4e00-\u9fa5\\w]{4})","*");
		}
		return username;
	}
	
	public static void main(String[] args) {
		System.out.println(UsernameEncryptionUtil.encryptionUsername("聂检华njh聂检华"));
	}
}
